/**
 * @author: akolonitsky
 * @date: 12/7/11 3:05 PM
 */
package controller {

    import model.AnalyticProxy;
    import model.LogProxy;
    import model.vo.ReportVO;

    import org.puremvc.as3.interfaces.INotification;
    import org.puremvc.as3.patterns.command.SimpleCommand;

    public class AnalyticGetCommand extends SimpleCommand
    {
        override public function execute(notification:INotification):void
        {
            super.execute(notification);

            var report:ReportVO = notification.getBody() is ReportVO ? notification.getBody() as ReportVO : null;
            var name:String = report ? report.title : notification.getBody() as String;

            var logProxy:LogProxy = facade.retrieveProxy(LogProxy.NAME) as LogProxy;
            var log:Array = null;
            if (report)
                log = logProxy.getLogRange(report.beginDate, report.endDate);
            else
                log = logProxy.records;

            var analytic:AnalyticProxy = facade.retrieveProxy(AnalyticProxy.NAME) as AnalyticProxy;
            analytic.updateReport(log, name);
        }
    }
}
